package com.itrus.spring.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author peigen
 * @since 2024/10/8
 */
@Slf4j
@Aspect
@Component
public class CostTimeAspect {

    @Around("execution(* com.itrus.spring.aop.service.*.*(..))")
    public Object cost(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        log.info("[{}#{}] cost {}ms ", joinPoint.getTarget().getClass().getName(), joinPoint.getSignature().getName(), (System.currentTimeMillis() - start));
        return result;
    }
}
